package com.prestamomo.vil.ppa.pmvilpage.pmfitter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.prestamomo.vil.ppa.R;
import com.prestamomo.vil.ppa.pmvilapi.PmvilSerConfig;

import java.util.List;

public class PmvilSourceFiter extends RecyclerView.Adapter<PmvilSourceFiter.PmvilSourHold> {
    private Context pmivlConts;
    private List<PmvilSerConfig.ExtInfoArrPmvil> pmvilSourList;

    public PmvilSourceFiter(Context pmivlConts, List<PmvilSerConfig.ExtInfoArrPmvil> pmvilSourList) {
        this.pmivlConts = pmivlConts;
        this.pmvilSourList = pmvilSourList;
    }

    @NonNull
    @Override
    public PmvilSourceFiter.PmvilSourHold onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new PmvilSourHold(LayoutInflater.from(pmivlConts).inflate(R.layout.source_pmvil_pop_item,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull PmvilSourceFiter.PmvilSourHold holder, int position) {
            holder.sourPmvilPopitemTv.setText(pmvilSourList.get(position).getPmvilname());
            holder.sourPmvilPopitemTv.setOnClickListener(v -> {
                if(sourceFilerIngter!=null){
                    sourceFilerIngter.setPmvilSourCheckBean(pmvilSourList.get(position));
                }
            });
    }

    @Override
    public int getItemCount() {
        return pmvilSourList==null?0: pmvilSourList.size();
    }

    public class PmvilSourHold extends RecyclerView.ViewHolder{
        private TextView sourPmvilPopitemTv;
        public PmvilSourHold(@NonNull View itemView) {
            super(itemView);
            sourPmvilPopitemTv = itemView.findViewById(R.id.source_pmvil_pop_item_tv);
        }
    }

    public interface SourceFilerIngter{
        void setPmvilSourCheckBean(PmvilSerConfig.ExtInfoArrPmvil pmvilSourPopBen);
    }

    private SourceFilerIngter sourceFilerIngter;

    public void setSourceFilerIngter(SourceFilerIngter sourceFilerIngter) {
        this.sourceFilerIngter = sourceFilerIngter;
    }
}
